package moudletest;

import org.junit.Test;
import pojo.LogBean;
import pojo.RuleAutomicParam;
import pojo.RuleParam;
import service.UserActionCountQuerySericeImpl;
import service.UserActionSequenceQueryServiceImpl;
import service.UserProfileQueryServiceImpl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

public class TestModule {


    /**
     * 查询画像并比对
     */

    @Test
    public void testuserprofilefromhbase() {
        // 000009             column=f:98k, timestamp=1621388492327, value=v80
        // 000009             column=f:990k, timestamp=1621388492327, value=v84
        HashMap<String, String> properties = new HashMap<>();
        // 99                      column=f:9k, timestamp=1621604818884, value=v23
           properties.put("9k", "v23");
        properties.put("99k", "v6");
        String deviceid = "99";
        String Eventid = "W";

        //LogBean参数
        LogBean logBean = new LogBean();
        logBean.setDeviceId(deviceid);
        logBean.setEventId(Eventid);

        //构造原子参数
        RuleAutomicParam ruleAutomicParam = new RuleAutomicParam();
        ruleAutomicParam.setProperties(properties);
        ruleAutomicParam.setEventId(Eventid);

        //构造规则
        RuleParam ruleParam = new RuleParam();
        ruleParam.setTriggerparam(ruleAutomicParam);
        ruleParam.setUserProfileParam(properties);
        UserProfileQueryServiceImpl userProfileQueryService = new UserProfileQueryServiceImpl();
        try {
            boolean b = userProfileQueryService.QueryUserProfileQueryFromHbase(logBean, ruleParam);

            System.out.println(b);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 行为次数查询服务测试
     * 000010	2	1
     * 000020	2	2
     */
    @Test
    public void testUserCount() {
        //模拟liststate<中多个LogBean>中多个LogBean

        // 构造几个明细事件
        LogBean logBean1 = new LogBean();
        logBean1.setEventId("A");
        HashMap<String, String> props1 = new HashMap<>();
        props1.put("p1", "v1");
        logBean1.setProperties(props1);


        LogBean logBean2 = new LogBean();
        logBean2.setEventId("A");
        HashMap<String, String> props2 = new HashMap<>();
        props2.put("p1", "v2");
        logBean2.setProperties(props2);


        LogBean logBean3 = new LogBean();
        logBean3.setEventId("B");
        HashMap<String, String> props3 = new HashMap<>();
        props3.put("p2", "v3");
        logBean3.setProperties(props3);


        LogBean logBean4 = new LogBean();
        logBean4.setEventId("B");
        HashMap<String, String> props4 = new HashMap<>();
        props4.put("p2", "v3");
        props4.put("p3", "v4");
        logBean4.setProperties(props4);


        ArrayList<LogBean> eventList = new ArrayList<>();
        eventList.add(logBean1);
        eventList.add(logBean2);
        eventList.add(logBean3);
        eventList.add(logBean4);


        // 构造2个规则原子条件
        RuleAutomicParam param1 = new RuleAutomicParam();
        param1.setEventId("A");
        HashMap<String, String> paramProps1 = new HashMap<>();
        paramProps1.put("p1", "v1");
        param1.setProperties(paramProps1);
        param1.setCount(2);

        RuleAutomicParam param2 = new RuleAutomicParam();
        param2.setEventId("B");
        HashMap<String, String> paramProps2 = new HashMap<>();
        paramProps2.put("p2", "v3");
        param2.setProperties(paramProps2);
        param2.setCount(2);

        ArrayList<RuleAutomicParam> ruleParams = new ArrayList<>();
        ruleParams.add(param1);
        ruleParams.add(param2);
//
//        RuleParam ruleParam = new RuleParam();
//        ruleParam.setUserActionParam(ruleAutomicParams);
        UserActionCountQuerySericeImpl userActionCountQuerySerice = new UserActionCountQuerySericeImpl();
        userActionCountQuerySerice.queryHelper(eventList, ruleParams);
        for (RuleAutomicParam ruleAutomicParam : ruleParams) {
            System.out.println(ruleAutomicParam.getEventId() + "\t" + ruleAutomicParam.getCount() + "\t" + ruleAutomicParam.getRealcount());
        }
    }


    /**
     * 系列测试
     */
    @Test

    public void testUserCountSequence() {
        //模拟liststate<中多个LogBean>中多个LogBean

        // 构造几个明细事件
        LogBean logBean1 = new LogBean();
        logBean1.setEventId("A");
        HashMap<String, String> props1 = new HashMap<>();
        props1.put("p2", "v1");
        logBean1.setProperties(props1);


        LogBean logBean2 = new LogBean();
        logBean2.setEventId("A");
        HashMap<String, String> props2 = new HashMap<>();
        props2.put("p1", "v2");
        logBean2.setProperties(props2);


        LogBean logBean3 = new LogBean();
        logBean3.setEventId("D");
        HashMap<String, String> props3 = new HashMap<>();
        props3.put("p4", "v6");
        logBean3.setProperties(props3);


        LogBean logBean4 = new LogBean();
        logBean4.setEventId("E");
        HashMap<String, String> props4 = new HashMap<>();
        props4.put("p5", "v8");
        logBean4.setProperties(props4);


        ArrayList<LogBean> eventList = new ArrayList<>();
        eventList.add(logBean1);
        eventList.add(logBean2);
        eventList.add(logBean3);
        eventList.add(logBean4);


        // 构造2个规则原子条件
        RuleAutomicParam param1 = new RuleAutomicParam();
        param1.setEventId("A");
        HashMap<String, String> paramProps1 = new HashMap<>();
        paramProps1.put("p1", "v2");
        param1.setProperties(paramProps1);

        RuleAutomicParam param2 = new RuleAutomicParam();
        param2.setEventId("D");
        HashMap<String, String> paramProps2 = new HashMap<>();
        paramProps2.put("p4", "v6");
        param2.setProperties(paramProps2);

        RuleAutomicParam param3 = new RuleAutomicParam();
        param3.setEventId("E");
        HashMap<String, String> paramProps3 = new HashMap<>();
        paramProps3.put("p5", "v8");
        param3.setProperties(paramProps3);

        ArrayList<RuleAutomicParam> ruleParams = new ArrayList<>();
        ruleParams.add(param1);
        ruleParams.add(param2);
        ruleParams.add(param3);


        RuleParam ruleParam = new RuleParam();
        ruleParam.setUserActionsequenceParam(ruleParams);

        UserActionSequenceQueryServiceImpl userActionSequenceQueryService = new UserActionSequenceQueryServiceImpl();

        int i = userActionSequenceQueryService.UserActionSequenceQueryFromStateHelper(eventList, ruleParam);
        System.out.println(">>>>>>>>>>>     "+i);


//        for (RuleAutomicParam ruleAutomicParam : ruleParams) {
//            System.out.println(ruleAutomicParam.getEventId() + "\t" + ruleAutomicParam.getCount() + "\t" + ruleAutomicParam.getRealcount());
//        }
    }


    /**
     * clickhouse查询数据模块逻辑测试和性能测试
     *
     */



    public  void  ClickHousequeryTest(){








    }


}


